package com.tsj.mvp.demo6;

import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.Log;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

/**
 * 兼容多个activity,因此需要对activity泛型
 * */
public abstract class BaseMvpActivity<V extends BaseView6,P extends BasePresenter6<V>> extends AppCompatActivity {

    private P presenter;
    private V view;

    @Override
    protected void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(this.presenter == null){
            this.presenter = initPresenter();
        }
        if(this.view ==null){
            this.view = initView();
        }
        if(this.presenter != null && this.view != null){
            this.presenter.attachView(this.view);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if(presenter != null && view != null){
            presenter.detachView();
        }
    }

    public P getPresenter(){
        return presenter;
    }

    public abstract P initPresenter();

    public abstract V initView();
}
